
<?php
if ($this->code == "0") {
    echo "<legend>";
    echo $this->msg;
    echo "</legend>";
} else
    echo $this->msg;

if ($this->code == "") {
    ?>

    <legend>TopUp Point</legend>
    <div class="row clearfix">
        <div class="col-md-8 column">
            <form method="post" id="frm" name="frm">
                <br>
                <!-- amount input-->
                <div class="form-group">                    
                    <input placeholder="Jumlah TopUp" class="form-control" type="text" name="amount" id="amount" onkeypress='return validateNumber(event)'></input>
                    <p class="help-block">Cth: 1500000 (Tanpa titik/koma)</p>
                </div>


                <div>
                    
                    <select id="bank_account_no" name="bank_account_no" class="form-control" required>
                        <option value="">== Bank Yang Ditransfer ==</option>
                            <?php

                           foreach ($this->bank as $oBank) {

                                    echo "<option value='".$oBank['account_num']."'>". $oBank['bank_acc_num'] ."</option>";
                           }
                           ?>
                        </select>
                </div>

                <div>
                    <input class="form-control" placeholder="Tanggal Transfer: DD-MM-YYYY" required type="text" name="tgl_trans" id="tgl_trans" data-options="required:true"></input>
                    <p class="help-block"></p>
                    
                </div>

                <!-- remark input-->
                <div class="form-group">

                    <div class="controls">
                        <textarea id="remark" name="remark" type="text" placeholder="Catatan/Keterangan"
                        class="form-control"></textarea>

                        <p class="help-block"></p>
                    </div>
                </div>

               <div>
                <label class="control-label">Kode keamanan</label>
               </div>

                <div>
                <?php

                require_once('Zend/Captcha/Image.php');

                $captcha = new Zend_Captcha_Image(array(
                    'wordLen' => 5,
                    'font'=> APPLICATION_PATH . '/../public/fonts/micross.ttf',
                    'imgDir'=> APPLICATION_PATH . '/../public/captcha/',
                    'imgUrl'=> '/captcha/',
                    'width' => 150,
                    'height' => 55,
                    'dotNoiseLevel' => 40,
                    'lineNoiseLevel' => 3
                    ));

                if (!empty($_POST)) {
                    if ($captcha->isValid($_POST['captcha'])) {
                        echo 'Passed CAPTCHA check<br>';
                    }
                }

                $idCapcay = $captcha->generate();

                echo $captcha->render(new Zend_View());
                //echo "&nbsp;<a href='#' id='refreshcaptcha'>Refresh</a>";
                ?>
            </div>
            <div>
                <label></label>
                <input class="form-control" placeholder="Tulis Kode keamanan disini" type="text" name="captcha[input]" id="captcha-input" data-options="required:true" required/>
                <input type="hidden" name="captcha[id]" value="<?php echo $idCapcay; ?>" />
            </div>

                <!-- submit btn-->
                <div class="form-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                            Submit</button>
                        <button class="btn btn-default" type="reset" id="btnReset" name="btnReset">
                            Reset</button>
                        <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>



            </form>



        </div>
    </div>

    <script>


        var tgl_trans = $('#tgl_trans').datepicker({
            format: 'dd-mm-yyyy'
            }).on('changeDate', function(ev) {
            tgl_trans.hide();
            }).data('datepicker');



        /* Attach a submit handler to the form */
        $("#frm").submit(function(event) {

            /* Stop form from submitting normally */
            event.preventDefault();

            /* Clear result div*/
            $("#div_result").html('');
            $("#btnSubmit").html('Memproses...');
            $("#btnSubmit").attr('disabled','disabled');

            /* Get some values from elements on the page: */
            var values = $(this).serialize();

            var msg = [];

            /* Send the data using post and put the results in a div */

            $.ajax({
                url: "<?php echo $this->baseUrl() ?>/rekening/topuppoint/",
                type: "post",
                data: values,
                success: function(response, opts){

                    //alert(response);

                    
                    var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                    if (cekSess < 0){
                        var cekStatus = response.toUpperCase().search("ERROR");

                        if (cekStatus < 0){
                            $("#div_content").html(response);
                        }else{

                            var resp = response.replace('ERROR', '');

                            msg.push('<span>'+resp+'</span>');
                            $.messager.alert('Info', msg.join('<br/>'));

                            //$("#div_result").html(resp);
                            $("#btnSubmit").removeAttr('disabled');
                            $("#btnSubmit").html('Submit');
                        }
                    }else{
                        location.href='<?php echo $this->baseUrl() ?>/index/login/msg/Session Timeout silahkan login kembali !';
                    }
                    
                },
                error:function(response, opts){
                    //alert("failure");
                    //$("#div_result").html(response);
                    msg.push('<span>'+response+'</span>');
                    $.messager.alert('Info', msg.join('<br/>'));

                    $("#btnSubmit").removeAttr('disabled');
                }
            });

        });

        function resetForm() {
            $('#frmWithdraw').form('clear');
        }

        $('#acc_num').change(function() {

            var accNum = $('#acc_num').val();

            if (accNum == 0) {
                $('#balance').val('');
                $('#balance2').val('');
                return;
            }

            $('#acc_num').attr('disabled', 'disabled');

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '<?php echo $this->baseUrl() ?>/jsondata/totalbalance',
                data: {accNum: accNum},
                success: function(result) {
                    var balance = result.balance;
                    var balance2 = result.balance2;

                    $('#balance').val(balance);
                    $('#balance2').val(balance2);

                    $('#acc_num').removeAttr('disabled');
                },
                failure: function(response, opts) {
                    $('#acc_num').removeAttr('disabled');
                    alert('server-side failure with status code ' + response.status);
                }
            });

        });

        function validateNumber(evt) {

            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }

        function validate(frm) {

            var msg = [];

            if ($('#acc_num').val() == "0")
                msg.push('<span>* Nomor Akun harus dipilih</span>');
            if ($('#tarik').val() == "")
                msg.push('<span>* Jumlah Penarikan harus diisi</span>');

            if ((eval($('#balance').val()) - (eval($('#tarik').val()) + eval($('#biaya').val()))) < eval($('#min_saldo').val()) || eval($('#balance').val()) < eval($('#min_saldo').val()))
                msg.push('<span>* Minimum Saldo tidak mencukupi</span>');

            if ((eval($('#tarik').val()) + eval($('#biaya').val())) > eval($('#balance').val()))
                msg.push('<span>* Jumlah Penarikan + Biaya lebih besar dari saldo</span>');
            if ($('#acc_bank_id').val() == "")
                msg.push('<span>* Bank harus dipilih</span>');
            if ($('#captcha-input').val() == "")
                msg.push('<span>* Kode keamanan harus diisi</span>');

            if (msg.length == 0)
                return true;
            else {
                //alert("Data tidak lengkap:\n\n" + msg);
                //$.messager.alert("Data tidak lengkap:\n\n" + msg);
                $.messager.alert('Info', msg.join('<br/>'));
                return false;
            }
        }


    </script>

<?php } ?>